import pygtk
pygtk.require('2.0')
import gtk
# import os, sy
import os, sys

class BaseGtkWindow:
        
    def delete_event(self, widget, event, data=None):
        # If you return FALSE in the "delete_event" signal handler, 
        # GTK will emit the "destroy" signal. Returning TRUE means you don't want the window to be destroyed.
        # This is useful for popping up 'are you sure you want to quit?' type dialogs.
        print("delete event occurred")
        
        # Change FALSE to TRUE and the main window will not be destroyed with a "delete_event".
        return False

    def destroy(self, widget, data=None):
        print("destroy signal occurred")
        gtk.main_quit()
        
    def __init__(self):        
        
        # create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    
        # When the window is given the "delete_event" signal (this is given by the window manager, usually by the "close" option, or on the titlebar), we ask it to call the delete_event () function as defined above. 
        # The data passed to the callback function is NULL and is ignored in the callback function.
        self.window.connect("delete_event", self.delete_event)
    
        # Here we connect the "destroy" event to a signal handler.  
        # This event occurs when we call gtk_widget_destroy() on the window, or if we return FALSE in the "delete_event" callback.
        self.window.connect("destroy", self.destroy)
        
    def main(self):
        # All PyGTK applications must have a gtk.main(). Control ends here and waits for an event to occur (like a key press or mouse event).
        gtk.main()